package com.ttbj.core.bean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ttbj.core.util.JsonTools;

/**
 * 
 * @author trzxcv@163.com
 * use example:
 *         JpushModel.newBuilder().setIsMessage(true).setRegistId("").joinContentList(list).build();
 *	alert:
 *		   if registId is null then all defult device to send 
 *
 */
public class JpushModel {
	  public final static Logger LOG = LoggerFactory.getLogger(JpushModel.class);
	private final Boolean isMessage;			//true:信息  false:通知
	private final String registId;				//单个registId
	private final String contentChain;	   		//拼接内容串
	private JpushModel( Boolean isMessage, String registId,String contentChain) {
		this.isMessage = isMessage;
		this.registId = registId;
		this.contentChain  =contentChain ;
	}

	public static Builder newBuilder() {
		return new Builder();
	}
	public Boolean getAll() {
		return isMessage;
	}

	public String getRegistId() {
		return registId;
	}

	public String getContentChain() {
		return contentChain;
	}
	public static class Builder {
		private Boolean isMessage;
		private String registId;
		private String contentChain;
		public Builder setIsMessage(Boolean isMessage) {
			this.isMessage = isMessage;
			return this;
		}

		public Builder setRegistId(String registId) {
			this.registId = registId;
			return this;
		}
		
		public Builder  joinContent(Object o) throws Exception{
			if(o == null){
				throw new Exception("推送的内容为空，请验证内容集合中是否存在元素");
			}
			contentChain=JsonTools.GsonString(o);
			LOG.info("推送的信息是：{}",contentChain);
			return this;
		}
		
		public JpushModel build() {
			return new JpushModel(isMessage, registId,contentChain);
		}
	}

}
